<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<%-- <%@taglib uri="spring.tld" prefix="spring"%> --%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String servletPath = (String)request.getAttribute("javax.servlet.forward.servlet_path");
String[] list = servletPath.split("\\/");
request.setAttribute("role",list[1]);
request.setAttribute("topMenuId",list[2]);
request.setAttribute("leftMenuId",list[3]);
%>

<!DOCTYPE html>
<html>
	<head>
		<base href="<%=basePath%>">

		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<title>培训章节</title>
		<meta name="keywords" content="">
		<link rel="shortcut icon"
		href="<%=basePath%>resources/images/favicon.ico" />
		<link href="resources/bootstrap/css/bootstrap-huan.css" rel="stylesheet">
		<link href="resources/font-awesome/css/font-awesome.min.css"
		rel="stylesheet">
		<link href="resources/css/style.css" rel="stylesheet">

		<link href="resources/css/exam.css" rel="stylesheet">
		<link href="resources/chart/morris.css" rel="stylesheet">
		<style type="text/css">
			.disable-btn, .enable-btn {
				text-decoration: underline;
			}

			.disable-btn, .enable-btn {
				cursor: pointer;
			}
		</style>
	</head>
	<body>
		<table class="table" style="font-size: 13px">
                <thead>
                    <tr>
                        <td>培训章节</td>
                        <td style="width: 65px;">操作</td>
                    </tr>
                </thead>
                <tbody>
                    <c:forEach items="${sectionList }" var="item">
                        <tr>
                            <td>
                                <a class="training-sections btn-sm" href="secure/training/${item.sectionId }" data-id="${item.sectionId }" >${item.sectionName }</a>
                            </td>
                            <td>
                                <c:choose>
                                    <c:when test="${sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.rolesName == 'ROLE_ADMIN'}">
                                        <a class="delete-training-section btn-sm btn-danger" data-id="${item.sectionId }" data-role="admin">删除</a>
                                    </c:when>
                                    <c:otherwise>
                                        <c:if test="${item.userId == sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.userid}">
                                            <a class="delete-training-section btn-sm btn-danger" data-id="${item.sectionId }" data-role="teacher">删除</a>
                                        </c:if>
                                        <c:if test="${item.userId != sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.userid}">
                                            <span class="btn-sm" data-id="${item.sectionId }" disabled="disabled"><i class="ace-icon fa fa-ban"></i></span>
                                        </c:if>
                                    </c:otherwise>
                                </c:choose>
                            </td>
                        </tr>
                    </c:forEach>


                </tbody>
                <tfoot>
                </tfoot>
            </table>

        <script>
            $(function() {

                $(".delete-training-section").click(function () {
                    if (confirm("该章节资料将一起删除，是否继续？")) {
                        $.ajax({
                            headers: {
                                'Accept': 'application/json',
                                'Content-Type': 'application/json'
                            },
                            type: "GET",
                            url: $(this).data("role")+"/common/training-section-delete-" + $(this).data("id"),
                            success: function (message, tst, jqXHR) {
                                if (!util.checkSessionOut(jqXHR))
                                    return false;
                                if (message.result == "success") {
                                    util.success("删除成功", function () {
                                        window.location.reload();
                                    });
                                } else {
                                    util.error("操作失败:" + message.result);
                                }
                            }
                        });

                    }
                });
            });
        </script>
	</body>
	
</html>